<?php

namespace App\Service\H5;

use App\Constants\ErrorCode;
use App\Model\ComplaintRecordLog;
use App\Model\User;
use App\Service\BaseService;

/**
 * 投诉列表
 */
class ComplainRecordLogListService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId() ;
        $to_user_id = $this->request->input('to_user_id', 0);
        //是否管理员权限
        if (!User::isSuperAdmin($userId)) {
            return $this->setError(ErrorCode::OP_NOT_VALID, '暂无操作权限');
        }
        $ret = ComplaintRecordLog::getRecord($to_user_id);
        $item = [];
        array_walk($ret,function ($value) use(&$item){
            $value['label'] = json_decode($value['label'],true) ?? [];
            $value['images'] = json_decode($value['images'],true) ?? [];
            $item[] = $value;
        });
        return [
            'data' => $item
        ];
    }
}
